cmd line tutorials - gencmd

cmd line tutorials - gencmd

The xargs Command

Unix-Linux Mac

The xargs command is used to execute commands on a list of arguments. It is a very useful tool for automating tasks and for processing data in bulk.

Syntax

The basic syntax for the xargs command is as follows:

xargs [options] <command> <arguments>

The <command> argument is the command that you want to execute on the list of arguments. The <arguments> argument is a list of arguments that you want to pass to the command.

Examples

Execute the rm command on the list of files in the directory “/tmp”.

find /tmp -type f | xargs rm

For more information on the xargs command and its options, please see the man page: man xargs.

With gencmd

gencmd list txt files and delete them

  • ls -l *.txt | xargs -i rm {}

gencmd find txt files and show files with hello within it

  • find . -type f -name “*.txt” | xargs grep -i hello